﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace skvote
{
    public partial class admin_title_modify : System.Web.UI.Page
    {
        private OleDbConnection connection = new conn().CreateConnection();
        protected void Page_Load(object sender, EventArgs e)
        {
            function.check();
        }
        public string title(string id)
        {
            string title = "";
            if (!string.IsNullOrEmpty(id))
            {
                try
                {
                    connection.Close();
                    connection.Open();
                    OleDbCommand cmd = new OleDbCommand("select * from xh_title where id="+Request["id"],connection);
                    OleDbDataReader dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        title = dr["title"].ToString();
                    }
                }
                finally
                {
                    connection.Close();
                }
            }
            return title;
        }
        public string ms(string id,string value)
        {
            string listtype = "";
            if (!string.IsNullOrEmpty(id))
            {
                try
                {
                    connection.Close();
                    connection.Open();
                    OleDbCommand cmd = new OleDbCommand("select * from xh_title where id=" + Request["id"], connection);
                    OleDbDataReader dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        listtype = dr["ms"].ToString().Trim();
                    }
                }
                finally
                {
                    connection.Close();
                }
            }
            if (listtype == value.Trim())
            {
                return " selected";
            }
            else
            {
                return "";
            }
        }
        public string ListType(string id, string value)
        {
            string listtype = "";
            if (!string.IsNullOrEmpty(id))
            {
                try
                {
                    connection.Close();
                    connection.Open();
                    OleDbCommand cmd = new OleDbCommand("select * from xh_title where id=" + Request["id"], connection);
                    OleDbDataReader dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        listtype = dr["listtype"].ToString().Trim();
                    }
                }
                finally
                {
                    connection.Close();
                }
            }
            if (listtype == value.Trim())
            {
                return " selected";
            }
            else
            {
                return "";
            }
        }
        public void ListRows(string id)
        {
            string value = "";
            if (!string.IsNullOrEmpty(id))
            {                
                try
                {
                    connection.Close();
                    connection.Open();
                    OleDbCommand cmd = new OleDbCommand("select * from xh_title where id=" + id, connection);
                    OleDbDataReader dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        value = dr["listrows"].ToString();
                    }
                }
                finally
                {
                    connection.Close();
                }
            }
            for (int i = 1; i <= 20; i++)
            {
                if (value == i.ToString().Trim())
                {
                    Response.Write("<option value='" + i.ToString().Trim() + "' selected>" + i.ToString().Trim() + "</option>");
                }
                else
                {
                    Response.Write("<option value='" + i.ToString().Trim() + "'>" + i.ToString().Trim() + "</option>");
                }
            }
        }

        protected void submit_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request["sid"]) && !string.IsNullOrEmpty("title") && !string.IsNullOrEmpty("ms") && !string.IsNullOrEmpty("listType") && !string.IsNullOrEmpty("listRows") && !string.IsNullOrEmpty("id"))
            {
                try
                {
                    connection.Close();
                    connection.Open();
                    OleDbCommand cmd = new OleDbCommand("select * from xh_title where title=\"" + Request["title"].Trim()+"\"", connection);
                    OleDbDataReader dr = cmd.ExecuteReader();
                    cmd = new OleDbCommand("update xh_title set sid=" + Request["sid"].Trim() + ",title=\"" + Request["title"].Trim() + "\",ms=" + Request["ms"].Trim() + ",listType=" + Request["listType"].Trim() + ",listRows=" + Request["listRows"].Trim() + " where id=" + Request["id"].Trim(), connection);
                    cmd.ExecuteNonQuery();
                    cmd.Dispose();                    
                }
                finally
                {
                    connection.Close();
                }
                function.successMsg("标题信息修改成功");
            }
        }
    }
}
